<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>注册</title>
  <!-- 导入jquery -->
  <script src="./libs/jquery-1.12.4.min.js"></script>
  <!-- 导入bootstrap -->
  <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css">
  <script src="./libs/bootstrap/js/bootstrap.min.js"></script>
  <!-- 导入art-template -->
  <script src="./libs/template-web.js"></script>
  <!-- 导入md5 -->
  <script src="./libs/md5.min.js"></script>
  <style>
    /* 把登录框往下压 */
    .my-panel {
      margin-top: 200px;
    }
  </style>
</head>

<body>
  <!-- bootstrap的容器  带版心的-->
  <div class="container">
    <!-- 栅格的行 -->
    <div class="row">
      <!-- 栅格的列 offset 列偏移 -->
      <div class="col-xs-6 col-xs-offset-3">
        <!-- 面板 -->
        <div class="panel panel-default panel-primary my-panel">
          <!-- 面板的标题 -->
          <div class="panel-heading">
            <h3 class="panel-title">登录CQ管理系统</h3>
          </div>
          <!-- 面板的内容 -->
          <div class="panel-body">
            <!-- 表单 -->
            <form class="form-horizontal" id="form">
              <div class="form-group">
                <label for="userName" class="col-sm-2 control-label">用户名</label>
                <div class="col-sm-10">
                  <input type="text" name="username" class="form-control" id="username" placeholder="王**">
                </div>
              </div>
              <div class="form-group">
                <label for="passWord" class="col-sm-2 control-label">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
                <div class="col-sm-10">
                  <input type="password" name="password" class="form-control" id="password" placeholder="密码">
                </div>
              </div>
              <div class="form-group">
                <div class="col-lg-offset-5 col-sm-offset-2 col-sm-10">
                  <input type="submit" class="btn btn-danger" id="register" value="注册">
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
</html>
<script>
  $(function(){
    $('#register').on('click',function (e) {
      e.preventDefault()
      let username=$('#username').val().trim()
    let password=$('#password').val().trim()
    if(username==''||password=='')return;
      $.ajax({
        url:'http://127.0.0.1:4099/register',
        type:'post',
        data:{
          username,
          password
        },
        success:function(backData){
          console.log(backData);
          if(backData.code==200){
            alert(backData.msg)
            localStorage.setItem('username', backData.username);
            localStorage.setItem('password', backData.password);

            window.location='./login.html'
            
          }
          
        }



      })
      })
   


  })



</script>